 
  

 






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=17 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:32 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
<head>
 <title>
  Java Practices -> Implementing equals
 </title>
 <link rel="stylesheet" type="text/css" href="../stylesheet8.css" media="all">
 
 <link rel="shortcut icon" href='../images/favicon.ico' type="image/vnd.microsoft.icon">
 <meta name="description" content="Concise presentations of java programming practices, tasks, and conventions, amply illustrated with syntax highlighted code examples.">
 
 <meta name='keywords' content='==,equals,java,java programming,java practices,java idiom,java style,java design patterns,java coding conventions,'>
 
 
</head>
 
<body>


<div class='menu-bar'>
 
  <a href='../home/HomeAction.html' title='Table of Contents'>Home</a> |
  <a href='../vote/VoteSummaryAction-2.html' title='View Poll Results'>Poll</a> |
   
  <A href='../feedback/FeedbackAction451f-2.html?Operation=Show' title='Send Your Feedback'>Wiki</a> |
  <b><a href='../source/SourceAction-2.html' title='Grab Source Code'>Source Code</a></b><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |

  <a href='http://www.web4j.com/Java_Web_Application_Framework_Overview.jsp?From=1' title='Free Download - Java Web Application Framework'><b>WEB4J</b></a> |
  
  <a href='http://www.date4j.net/' title='Replacement for java.util.Date'><b>DATE4J</b></a> |

   <a href='../references/ReferencesAction-2.html' title='References'>Links</a>
   
  <form action='http://www.javapractices.com/search/SearchAction.do' method='get' class='search-form'>
   <input type='text' name='SearchTerms' value="" size=12 maxlength=50 class='search'>
   <input type='submit' value="Search">
  </form>
 
</div>

<P>



  

 






<p class="display-messages">

 

 

</p>


<div class="main-layout">
 
   

 




<div class='page-title'>Implementing equals</div>

<div class='main-body'>
 
<br>All objects have both <em>identity</em> (the object's location in memory) and
<em>state</em> (the object's data). The <tt>==</tt> operator always compares identity.
The default implementation of <tt><a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html#equals()">equals</a></tt>
compares identity as well.

<p>Sometimes the default implementation of <tt>equals</tt> has the desired
behaviour (as in a <a href="TopicAction2161-2.html">type-safe enumeration</a>, for
example), but <span class='highlight'><tt>equals</tt> should usually compare state, not identity.
This is particularly true for <a href="TopicActiond08d-2.html">"data-centric" classes</a>
which map to database records.</span>

<p><tt><a href="TopicAction78db-2.html">hashCode</a></tt> and <tt>equals</tt> are
closely related :

<ul>
<li>if you override <tt>equals</tt>, you must override <tt>hashCode</tt>.</li>
<li><tt>hashCode</tt> must generate equal values for equal objects.</li>
<li><tt>equals</tt> and <tt>hashCode</tt> must depend on the same set of "significant" fields. You 
must use the same set of fields in both of these methods. You are not required to use all fields. 
For example, a calculated field that depends on others should very likely be omitted from <tt>equals</tt> 
and <tt>hashCode</tt>.
</ul>

Objects placed in a <tt>List</tt> , <tt>Set</tt>, or <tt>Map</tt> (as either
a key or value) should have an appropriate definition of <tt>equals</tt>.
(See, for example, the javadoc for <tt><a href="http://java.sun.com/javase/6/docs/api/java/util/Collection.html#contains(java.lang.Object)">Collection.contains</a></tt>
, <tt><a href="http://java.sun.com/javase/6/docs/api/java/util/Map.html#containsKey(java.lang.Object)">Map.containsKey</a></tt>,
and <tt><a href="http://java.sun.com/javase/6/docs/api/java/util/Map.html#containsValue(java.lang.Object)">Map.containsValue</a></tt>
.)

<p>If you extend a <i>concrete</i> class, and add a new field which contributes
to <tt>equals</tt>, then it is not possible to write a perfectly correct
<tt>equals</tt>
method for the new class. Instead, you should use composition instead of
inheritance. (See <i><a href="http://www.amazon.com/exec/obidos/ASIN/0201310058/ref=nosim/javapractices-20">Effective
Java</a></i> by Joshua Bloch for more information.)

<p>When implementing <tt>equals</tt>, fields are compared differently, according to their type:
<ul>
<li>
object fields, including collections : use <tt>equals</tt></li>

<li>
<a href="TopicAction2161-2.html">type-safe enumerations</a> : use either <tt>equals</tt>
or <tt>==</tt> (they amount to the same thing, in this case)</li>

<li>
possibly-null object fields : use both <tt>==</tt> and <tt>equals</tt></li>

<li>
array fields : use <tt><a href="http://java.sun.com/javase/6/docs/api/java/util/Arrays.html">Arrays</a>.equals</tt></li>

<li>
primitive fields other than <tt>float</tt> or <tt>double</tt> : use <tt>==</tt></li>

<li>
<tt>float</tt> : convert to <tt>int</tt> using <tt>Float.<a href="http://java.sun.com/javase/6/docs/api/java/lang/Float.html#floatToIntBits(float)">floatToIntBits</a></tt>,
then use <tt>==</tt></li>

<li>
<tt>double</tt> :&nbsp; convert to <tt>long</tt> using <tt>Double.<a href="http://java.sun.com/javase/6/docs/api/java/lang/Double.html#doubleToLongBits(double)">doubleToLongBits</a></tt>,
then use <tt>==</tt></li>
</ul>

It is worth noting that if fields are implemented with wrapper classes
(<tt>Integer</tt>, <tt>Boolean</tt>, and so on), then implementation of
<tt>equals</tt>
is simpler, since there is only one case : calling the
<tt>equals</tt>
method recursively. (The <tt><a href="TopicAction3eed-2.html">compareTo</a></tt> method
is also simplified in this case.)

<P>In an <tt>equals</tt> method, it is usually worthwhile to <em>order</em> field comparisons 
such that the most significant comparisons are performed first. That is, fields most 
likely to differ should be evaluated first. This allows the 
<a href='http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5247'><tt>&&</tt></a> 
"short-circuit" logical operator to minimize execution time.

<p><b>Example 1</b>

<p>The above policies can be collected in a utility class :
<br>
<PRE>

<span class='keyword'>import</span> java.util.Arrays;

<span class='comment'>/**
* Collected methods which allow easy implementation of &lt;code&gt;equals&lt;/code&gt;.
*
* Example use case in a class called Car:
* &lt;pre&gt;
public boolean equals(Object aThat){
  if ( this == aThat ) return true;
  if ( !(aThat instanceof Car) ) return false;
  Car that = (Car)aThat;
  return
    EqualsUtil.areEqual(this.fName, that.fName) &&
    EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors) &&
    EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage) &&
    EqualsUtil.areEqual(this.fColor, that.fColor) &&
    Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); //array!
}
* &lt;/pre&gt;
*
* &lt;em&gt;Arrays are not handled by this class&lt;/em&gt;.
* This is because the &lt;code&gt;Arrays.equals&lt;/code&gt; methods should be used for
* array fields.
*/</span>
<span class='keyword'>public</span> <span class='keyword'>final</span> <span class='keyword'>class</span> EqualsUtil {

  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(<span class='keyword'>boolean</span> aThis, <span class='keyword'>boolean</span> aThat){
    <span class='comment'>//System.out.println("boolean");
</span>    <span class='keyword'>return</span> aThis == aThat;
  }

  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(<span class='keyword'>char</span> aThis, <span class='keyword'>char</span> aThat){
    <span class='comment'>//System.out.println("char");
</span>    <span class='keyword'>return</span> aThis == aThat;
  }

  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(<span class='keyword'>long</span> aThis, <span class='keyword'>long</span> aThat){
    <span class='comment'>/*
    * Implementation Note
    * Note that byte, short, and int are handled by this method, through
    * implicit conversion.
    */</span>
    <span class='comment'>//System.out.println("long");
</span>    <span class='keyword'>return</span> aThis == aThat;
  }

  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(<span class='keyword'>float</span> aThis, <span class='keyword'>float</span> aThat){
    <span class='comment'>//System.out.println("float");
</span>    <span class='keyword'>return</span> Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
  }

  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(<span class='keyword'>double</span> aThis, <span class='keyword'>double</span> aThat){
    <span class='comment'>//System.out.println("double");
</span>    <span class='keyword'>return</span> Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat);
  }

  <span class='comment'>/**
  * Possibly-null object field.
  *
  * Includes type-safe enumerations and collections, but does not include
  * arrays. See class comment.
  */</span>
  <span class='keyword'>static</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> areEqual(Object aThis, Object aThat){
    <span class='comment'>//System.out.println("Object");
</span>    <span class='keyword'>return</span> aThis == <span class='keyword'>null</span> ? aThat == <span class='keyword'>null</span> : aThis.equals(aThat);
  }
}
 
</PRE>
<br>
<br><tt>Car</tt> is a class which uses <tt>EqualsUtil</tt> to implement
its <tt>equals</tt> method :
<br>
<PRE>

<span class='keyword'>import</span> java.util.*;

<span class='keyword'>public</span> <span class='keyword'>final</span> <span class='keyword'>class</span> Car {

  <span class='keyword'>public</span> Car (
    String aName, <span class='keyword'>int</span> aNumDoors, List&lt;String&gt; aOptions,
    <span class='keyword'>double</span> aGasMileage, String aColor, Date[] aMaintenanceChecks
  ){
    fName = aName;
    fNumDoors = aNumDoors;
    fOptions = <span class='keyword'>new</span> ArrayList&lt;String&gt;(aOptions);
    fGasMileage = aGasMileage;
    fColor = aColor;
    fMaintenanceChecks = <span class='keyword'>new</span> Date[aMaintenanceChecks.length];
    <span class='keyword'>for</span> (<span class='keyword'>int</span> idx=<span class='literal'>0</span>; idx &lt; aMaintenanceChecks.length; ++idx) {
      fMaintenanceChecks[idx] = <span class='keyword'>new</span> Date( aMaintenanceChecks[idx].getTime() );
    }
  }

  <span class='keyword'>@Override</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> equals(Object aThat) {
    <span class='comment'>//check for self-comparison
</span>    <span class='keyword'>if</span> ( <span class='keyword'>this</span> == aThat ) <span class='keyword'>return</span> <span class='keyword'>true</span>;

    <span class='comment'>//use instanceof instead of getClass here for two reasons
</span>    <span class='comment'>//1. if need be, it can match any supertype, and not just one class;
</span>    <span class='comment'>//2. it renders an explict check for "that == null" redundant, since
</span>    <span class='comment'>//it does the check for null already - "null instanceof [type]" always
</span>    <span class='comment'>//returns false. (See Effective Java by Joshua Bloch.)
</span>    <span class='keyword'>if</span> ( !(aThat <span class='keyword'>instanceof</span> Car) ) <span class='keyword'>return</span> <span class='keyword'>false</span>;
    <span class='comment'>//Alternative to the above line :
</span>    <span class='comment'>//if ( aThat == null || aThat.getClass() != this.getClass() ) return false;
</span>
    <span class='comment'>//cast to native object is now safe
</span>    Car that = (Car)aThat;

    <span class='comment'>//now a proper field-by-field evaluation can be made
</span>    <span class='keyword'>return</span>
      EqualsUtil.areEqual(<span class='keyword'>this</span>.fName, that.fName) &amp;&amp;
      EqualsUtil.areEqual(<span class='keyword'>this</span>.fNumDoors, that.fNumDoors) &amp;&amp;
      EqualsUtil.areEqual(<span class='keyword'>this</span>.fOptions, that.fOptions) &amp;&amp;
      EqualsUtil.areEqual(<span class='keyword'>this</span>.fGasMileage, that.fGasMileage) &amp;&amp;
      EqualsUtil.areEqual(<span class='keyword'>this</span>.fColor, that.fColor) &amp;&amp;
      Arrays.equals(<span class='keyword'>this</span>.fMaintenanceChecks, that.fMaintenanceChecks);
  }

  <span class='comment'>//..other methods elided
</span>
  <span class='comment'>// PRIVATE //
</span>
  <span class='comment'>/**
  * The following fields are chosen to exercise most of the different
  * cases.
  */</span>
  <span class='keyword'>private</span> String fName;
  <span class='keyword'>private</span> <span class='keyword'>int</span> fNumDoors;
  <span class='keyword'>private</span> List&lt;String&gt; fOptions;
  <span class='keyword'>private</span> <span class='keyword'>double</span> fGasMileage;
  <span class='keyword'>private</span> String fColor; <span class='comment'>//treat as possibly-null
</span>  <span class='keyword'>private</span> Date[] fMaintenanceChecks;

  <span class='comment'>/**
  * Exercise the equals method.
  */</span>
  <span class='keyword'>public</span> <span class='keyword'>static</span> <span class='keyword'>void</span> main (String... aArguments) {
    List&lt;String&gt; options = <span class='keyword'>new</span> ArrayList&lt;String&gt;();
    options.add(<span class='literal'>"sunroof"</span>);
    Date[] dates = <span class='keyword'>new</span> Date[<span class='literal'>1</span>];
    dates[<span class='literal'>0</span>] = <span class='keyword'>new</span> Date();

    <span class='comment'>//Create a bunch of Cars; only one and two should be equal
</span>    Car one = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//two is equal to one
</span>    Car two = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//three has a differs in fName only
</span>    Car three = <span class='keyword'>new</span> Car(<span class='literal'>"Pontiac"</span>, <span class='literal'>2</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//four differs in fNumDoors only
</span>    Car four = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>4</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//five differs in fOptions only
</span>    List&lt;String&gt; optionsTwo = <span class='keyword'>new</span> ArrayList&lt;String&gt;();
    optionsTwo.add(<span class='literal'>"air conditioning"</span>);
    Car five = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, optionsTwo, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//six differs in fGasMileage only
</span>    Car six = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, options, <span class='literal'>22.1</span>, <span class='literal'>"Green"</span>, dates);

    <span class='comment'>//seven differs in fColor only
</span>    Car seven = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Fuchsia"</span>, dates);

    <span class='comment'>//eight differs in fMaintenanceChecks only
</span>    Date[] datesTwo = <span class='keyword'>new</span> Date[<span class='literal'>1</span>];
    datesTwo[<span class='literal'>0</span>] = <span class='keyword'>new</span> Date(<span class='literal'>1000000</span>);
    Car eight = <span class='keyword'>new</span> Car(<span class='literal'>"Nissan"</span>, <span class='literal'>2</span>, options, <span class='literal'>46.3</span>, <span class='literal'>"Green"</span>, datesTwo);

    System.out.println( <span class='literal'>"one = one: "</span> + one.equals(one) );
    System.out.println( <span class='literal'>"one = two: "</span> + one.equals(two) );
    System.out.println( <span class='literal'>"two = one: "</span> + two.equals(one) );
    System.out.println( <span class='literal'>"one = three: "</span> + one.equals(three) );
    System.out.println( <span class='literal'>"one = four: "</span> + one.equals(four) );
    System.out.println( <span class='literal'>"one = five: "</span> + one.equals(five) );
    System.out.println( <span class='literal'>"one = six: "</span> + one.equals(six) );
    System.out.println( <span class='literal'>"one = seven: "</span> + one.equals(seven) );
    System.out.println( <span class='literal'>"one = eight: "</span> + one.equals(eight) );
    System.out.println( <span class='literal'>"one = null: "</span> + one.equals(<span class='keyword'>null</span>) );
  }
} 
</PRE>
<br>
<br>An example run of this class demonstrates that only objects <tt>one</tt>
and <tt>two</tt> are equal :
<br><tt>one = one: true</tt>
<br><tt>one = two: true</tt>
<br><tt>two = one: true</tt>
<br><tt>one = three: false</tt>
<br><tt>one = four: false</tt>
<br><tt>one = five: false</tt>
<br><tt>one = six: false</tt>
<br><tt>one = seven: false</tt>
<br><tt>one = eight: false</tt>
<br><tt>one = null: false</tt>

<P><b>Example 2</b>
<P>The <a href='TopicAction5f31-2.html'>WEB4J</a> tool has a utility class for implementing <tt>equals</tt>. The following is an 
example of a Model Object implemented with WEB4J. 

<P>Items to note regarding this <tt>equals</tt> method:
<ul>
<li>it reads at a slightly higher level
<li>it is easier to remember, and easier to write
<li>it does not use <a href='TopicActione309-2.html'>multiple return statements</a>
<li>the fields used in <tt>equals</tt> and <tt>hashCode</tt> are clearly 'in sync' (as they must be), 
since they both call the same method named <tt>getSignificantFields()</tt>
</ul>
<br>
<PRE>

<span class='keyword'>package</span> hirondelle.fish.main.discussion; 

<span class='keyword'>import</span> java.util.*;
<span class='keyword'>import</span> hirondelle.web4j.model.ModelCtorException;
<span class='keyword'>import</span> hirondelle.web4j.model.ModelUtil;
<span class='keyword'>import</span> hirondelle.web4j.model.Check;
<span class='keyword'>import</span> hirondelle.web4j.security.SafeText;
<span class='keyword'>import</span> <span class='keyword'>static</span> hirondelle.web4j.util.Consts.FAILS;

<span class='comment'>/** 
 Comment posted by a possibly-anonymous user.
*/</span>
<span class='keyword'>public</span> <span class='keyword'>final</span> <span class='keyword'>class</span> Comment { 

  <span class='comment'>/**
   Constructor. 
     
   @param aUserName identifies the logged in user posting the comment. 
   @param aBody the comment, must have content.
   @param aDate date and time when the message was posted.
  */</span>
  <span class='keyword'>public</span> Comment (
    SafeText aUserName, SafeText aBody, Date aDate
  ) <span class='keyword'>throws</span> ModelCtorException {
    fUserName = aUserName;
    fBody = aBody;
    fDate = aDate.getTime();
    validateState();
  }

  <span class='comment'>/** Return the logged in user name passed to the constructor. */</span>
  <span class='keyword'>public</span> SafeText getUserName() {
    <span class='keyword'>return</span> fUserName;
  }

  <span class='comment'>/** Return the body of the message passed to the constructor.  */</span>
  <span class='keyword'>public</span> SafeText getBody() {
    <span class='keyword'>return</span> fBody;
  }

  <span class='comment'>/**
   Return a &lt;a href="http://www.javapractices.com/Topic15.cjp"&gt;defensive copy&lt;/a&gt; 
   of the date passed to the constructor.
   
   &lt;P&gt;The caller may change the state of the returned value, without affecting 
   the internals of this &lt;tt&gt;Comment&lt;/tt&gt;. Such copying is needed since 
   a {@link Date} is a mutable object.
  */</span>
  <span class='keyword'>public</span> Date getDate() {
    <span class='comment'>// the returned object is independent of fDate
</span>    <span class='keyword'>return</span> <span class='keyword'>new</span> Date(fDate);
  }

  <span class='comment'>/** Intended for debugging only. */</span>
  <span class='keyword'>@Override</span> <span class='keyword'>public</span> String toString() {
    <span class='keyword'>return</span> ModelUtil.toStringFor(<span class='keyword'>this</span>);
  }

  <span class='keyword'>@Override</span> <span class='keyword'>public</span> <span class='keyword'>boolean</span> equals( Object aThat ) {
    Boolean result = ModelUtil.quickEquals(<span class='keyword'>this</span>, aThat);
    <span class='keyword'>if</span> ( result == <span class='keyword'>null</span> ){
      Comment that = (Comment) aThat;
      result = ModelUtil.equalsFor(
        <span class='keyword'>this</span>.getSignificantFields(), that.getSignificantFields()
      );
    }
    <span class='keyword'>return</span> result;    
  }

  <span class='keyword'>@Override</span> <span class='keyword'>public</span> <span class='keyword'>int</span> hashCode() {
    <span class='keyword'>if</span> ( fHashCode == <span class='literal'>0</span> ) {
      fHashCode = ModelUtil.hashCodeFor(getSignificantFields());
    }
    <span class='keyword'>return</span> fHashCode;
  }

  <span class='comment'>// PRIVATE // 
</span>  <span class='keyword'>private</span> <span class='keyword'>final</span> SafeText fUserName;
  <span class='keyword'>private</span> <span class='keyword'>final</span> SafeText fBody;
  <span class='comment'>/** Long is used here instead of Date in order to ensure immutability.*/</span>
  <span class='keyword'>private</span> <span class='keyword'>final</span> <span class='keyword'>long</span> fDate;
  <span class='keyword'>private</span> <span class='keyword'>int</span> fHashCode;
  
  <span class='keyword'>private</span> Object[] getSignificantFields(){
    <span class='keyword'>return</span> <span class='keyword'>new</span> Object[] {fUserName, fBody, <span class='keyword'>new</span> Date(fDate)};
  }
  
  <span class='keyword'>private</span> <span class='keyword'>void</span> validateState() <span class='keyword'>throws</span> ModelCtorException {
    ModelCtorException ex = <span class='keyword'>new</span> ModelCtorException();
    <span class='keyword'>if</span>( FAILS ==  Check.required(fUserName) ) {
      ex.add(<span class='literal'>"User name must have content."</span>);
    }
    <span class='keyword'>if</span> ( FAILS == Check.required(fBody) ) {
      ex.add(<span class='literal'>"Comment body must have content."</span>);
    }
    <span class='keyword'>if</span> ( ! ex.isEmpty() ) <span class='keyword'>throw</span> ex;
  }
}
 
</PRE>
<br>
<br>
<br>

</div>




<div class='topic-section'>See Also :</div>
<div class='main-body'>
 
  
  <a href='TopicAction3eed-2.html?Id=10'>Implementing compareTo</a> <br>
 
  
  <a href='TopicAction78db-2.html?Id=28'>Implementing hashCode</a> <br>
 
  
  <a href='TopicAction3d83-2.html?Id=31'>Beware of instanceof operator</a> <br>
 
  
  <a href='TopicActione309-2.html?Id=114'>Multiple return statements</a> <br>
 
  
  <a href='TopicActionf6e8-2.html?Id=197'>Use boxing with care</a> <br>
 
</div>


<div class='topic-section'>Would you use this technique?</div>
<div class='main-body'>
  
  <form action="http://www.javapractices.com/vote/AddVoteAction.do" method='post'>
    Yes<input type='radio' name='Choice' value='Y' >
    &nbsp;&nbsp;No<input type='radio' name='Choice' value='N'>
    &nbsp;&nbsp;Undecided<input type='radio' name='Choice' value="?" >
    &nbsp;&nbsp;<input type=submit value="Vote" >
    <input type='hidden' name='Operation' value='Apply'>
    <input type='hidden' name='TopicId' value='17'>
  </form>
</div>

<div style='height:10.0em;'></div>

 
 
</div>

  

 





<div align='center' class='legalese'>  
&copy; 2011 Hirondelle Systems |
<a href='../source/SourceAction-2.html'><b>Source Code</b></a><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |
<a href="mailto:webmaster@javapractices.com">Contact</a> |
<a href="http://creativecommons.org/licenses/by-nc-sa/1.0/">License</a> |
<a href='../apps/cjp.rss'>RSS</a>
<!-- ukey="2AC36CD2" -->
<!-- ckey="16DF3D87" -->
<br>

 Individual code snippets can be used under this <a href='../LICENSE.txt'>BSD license</a> - Last updated on June 6, 2010.<br>
 Over 150,000 unique IPs last month - <span title='Java Practices 2.6.5, Mon May 16 00:00:00 EDT 2011'>Built with</span> <a href='http://www.web4j.com/'>WEB4J</a>.<br>
 - In Memoriam : Bill Dirani -
</div>

<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2633428-1";
urchinTracker();
</script>



</body>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=17 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:34 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
</html>
